/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.openams.server.ejbs;

import java.util.Collection;
import java.util.Date;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.openams.server.common.UUIDGenerator;
import org.openams.server.entity.DatasetTemplate;

/**
 *
 * @author mike
 */
@Stateless
@LocalBean
public class DatasetTemplateBean {

    @PersistenceContext(unitName = "org.openams.server_OpenAMSServer_ejb_1.0-SNAPSHOTPU")
    private EntityManager em;
    
    
    public void addDatasetTemplate(String name, String author, String description)  {
        DatasetTemplate newTemplate = new DatasetTemplate();
        newTemplate.setDatasetTemplateAuthor(author);
        newTemplate.setDatasetTemplateName(name);
        newTemplate.setDatesetTemplateDescription(description);        
        newTemplate.setDatasetTemplateGlobalID(UUIDGenerator.get36CharUUID());
        newTemplate.setDatasetTemplateCreationDate(new Date());
        
        em.persist(newTemplate);
    }
    public void persist(Object object) {
        em.persist(object);
    }

    public Collection<DatasetTemplate> getDatasetTemplates() {
        return em.createQuery(em.getCriteriaBuilder().createQuery(DatasetTemplate.class)).getResultList();
    }
}
